home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Caml Light 0.61 / Source / src / appli / camlmenus.c next >
Encoding:
C/C++ Source or Header  |  1993-08-31  |  2.5 KB  |  111 lines  |  [TEXT/MPS ]

  1. #include <Files.h>
  2. #include <StdLib.h>
  3. #include <Resources.h>
  4. #include <StandardFile.h>
  5. #include "ui.h"
  6.  
  7. void CenterRect (Rect *r);
  8.  
  9. static pascal Boolean source_filter (ParmBlkPtr pb)
  10. {
  11.   char len = pb->fileParam.ioNamePtr [0];
  12.   if (len >= 3
  13.       && pb->fileParam.ioNamePtr [len] == 'l'
  14.       && pb->fileParam.ioNamePtr [len - 1] == 'm'
  15.       && pb->fileParam.ioNamePtr [len - 2] == '.'){
  16.     return 0;
  17.   }else{
  18.     return 1;
  19.   }
  20. }
  21.  
  22. static pascal Boolean object_filter (ParmBlkPtr pb)
  23. {
  24.   char len = pb->fileParam.ioNamePtr [0];
  25.   if (len >= 3
  26.       && pb->fileParam.ioNamePtr [len] == 'o'
  27.       && pb->fileParam.ioNamePtr [len - 1] == 'z'
  28.       && pb->fileParam.ioNamePtr [len - 2] == '.'){
  29.     return 0;
  30.   }else{
  31.     return 1;
  32.   }
  33. }
  34.  
  35. extern char *get_wd_name (short wd_refnum, char *postfix);
  36.  
  37. static char postfix [] = ":";
  38. static char nocd_template [] = "%s \"%s\";;";
  39. static char cd_template [] = "cd \"%s\"; %s \"%s\";;";
  40.  
  41. void do_file (char *command, long type, pascal Boolean (*filter) (ParmBlkPtr))
  42. {
  43.   DialogTHndl the_dialog;
  44.   Point there;
  45.   SFTypeList type_list;
  46.   SFReply reply;
  47.   short cur_vol;
  48.   Rect sb = qd.screenBits.bounds;
  49.   char *buf, *dir;
  50.  
  51.   the_dialog = (DialogTHndl) GetResource ('DLOG', getDlgID);
  52.   if (the_dialog != nil && *the_dialog != nil){
  53.     Rect *r = &(*the_dialog)->boundsRect;
  54.     
  55.     CenterRect (r);
  56.     there.h = r->left;
  57.     there.v = r->top;
  58.   }else{
  59.     there.h = 200;
  60.     there.v = 100;
  61.   }
  62.   type_list [0] = type;
  63.   SFGetFile (there, "\p", filter, 1, type_list, nil, &reply);
  64.   if (!reply.good) return;
  65.   p2cstr (reply.fName);
  66.   GetVol (NULL, &cur_vol);
  67.   if (cur_vol == reply.vRefNum){
  68.     buf = malloc (sizeof (nocd_template) - 4
  69.           + strlen (command)
  70.           + strlen (reply.fName));
  71.     if (buf == NULL) return;
  72.     sprintf (buf, nocd_template, command, reply.fName);
  73.   }else{
  74.     dir = get_wd_name (reply.vRefNum, postfix);
  75.     buf = malloc (sizeof (cd_template) - 6
  76.           + strlen (dir)
  77.           + strlen (command)
  78.           + strlen (reply.fName));
  79.     if (buf == NULL) return;
  80.     sprintf (buf, cd_template, dir, command, reply.fName);
  81.     if (dir != postfix) free (dir - 1);           /* cf.get_wd_name */
  82.   }
  83.   send_to_caml (buf);
  84.   free (buf);
  85. }
  86.  
  87. void do_include (void)
  88. {
  89.   do_file ("include", 'TEXT', source_filter);
  90. }
  91.  
  92. void do_compile (void)
  93. {
  94.   do_file ("compile", 'TEXT', source_filter);
  95. }
  96.  
  97. void do_load (void)
  98. {
  99.   do_file ("load", 'TEXT', source_filter);
  100. }
  101.  
  102. void do_load_object (void)
  103. {
  104.   do_file ("load_object", '\0\0\0\0', object_filter);
  105. }
  106.  
  107. void do_gc (void)
  108. {
  109.   send_to_caml ("gc();gc();;");
  110. }
  111.